#!/usr/bin/python

import wx
import time
from Myconfig import *


class App(wx.App):
	def OnInit(self):
		frame = MyFrame()
		frame.Show()
		return True

class MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "Cpu  Memmory", size=(1400, 900))
        self.panel = wx.Panel(self, -1)

        #init button
        #self.ok = wx.Button(self.panel, -1, "OK", size=wx.DefaultSize)

        #init static
	font = wx.Font(10, wx.ROMAN, wx.NORMAL, wx.BOLD)
	self.sproduct = wx.StaticText(self.panel, -1, "Product", size=wx.DefaultSize)
	self.sproduct.SetFont(font)
        
        self.sbug = wx.StaticText(self.panel, -1, "Bug Number", size=wx.DefaultSize)
	self.sbug.SetFont(font)

        #self.bug = wx.TextCtrl(self.panel, -1, "", size=wx.DefaultSize)

       
        # timer
        self.Bind(wx.EVT_PAINT, self.OnPaint)
        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)
        self.timer.Start(1000)

        #init picture
        #self.img1 = wx.Image("simpleline.png", wx.BITMAP_TYPE_ANY)
        #self.sb1 = wx.StaticBitmap(self.panel, -1, wx.BitmapFromImage(self.img1),(400,200),(400,300))
        #####################################################################
		#const wxPoint &  	pos = wxDefaultPosition,
		#const wxSize &  	size = wxDefaultSize, 
  			

        
        self.cpuPics=[['cpuroundmeter.png',(Myconfig.meterpointx,Myconfig.meterpointy),(Myconfig.meterpointwidth,Myconfig.meterpointheigth)], \
            ['cpusimpleline.png',(Myconfig.simplelinepointx,Myconfig.simplelinepointy),(Myconfig.simplelinepointwidth,Myconfig.simplelinepointheigth)], \
            ['memroundmeter.png',(Myconfig.meterpointx,Myconfig.meterpointy+250),(Myconfig.meterpointwidth,Myconfig.meterpointheigth)], \
            ['cpumultiline.png',(Myconfig.simplelinepointx,Myconfig.simplelinepointy+250+250),(Myconfig.simplelinepointwidth,Myconfig.multilinepointheigth)], \
            ['memsimplearea.png',(Myconfig.simplelinepointx,Myconfig.simplelinepointy+250),(Myconfig.simplelinepointwidth,Myconfig.simplelinepointheigth)]]

        try :
            for item in self.cpuPics:  
                    mypath = './out/'
                    img = wx.Image(mypath+item[0], wx.BITMAP_TYPE_ANY)
                    sb = wx.StaticBitmap(self.panel, -1, wx.BitmapFromImage(img),pos=item[1],size=item[2])
        except :
            return
            

        #self.mylayout()


    def mylayout(self):
        flag1 = wx.LEFT | wx.TOP | wx.BOTTOM | wx.RIGHT |wx.EXPAND
	flag2 = wx.LEFT | wx.TOP | wx.BOTTOM | wx.RIGHT
	border1 = 2;
        hbox1 = wx.BoxSizer()
	hbox1.Add(self.sproduct, proportion=0, flag=flag1, border=border1)

	hbox1.Add(self.sbug, proportion=0, flag=flag1, border=border1)
        hbox1.Add(self.bug, proportion=0, flag=flag1, border=border1)

        hbox2 = wx.BoxSizer()
        hbox2.Add(self.sb1, proportion=0, flag=flag1, border=border1)


        vbox = wx.BoxSizer(wx.VERTICAL)
	vbox.Add(hbox1, proportion=0, flag=flag2, border=border1)
        vbox.Add(hbox2, proportion=0, flag=flag2, border=border1)

	self.panel.SetSizer(vbox)

    def OnOk(self, event):
        print 'on ok'
	
    def Draw(self, dc):
        #print 'draw'
        t = time.localtime(time.time())
        st = time.strftime("%I:%M:%S", t)
        #self.bug.SetValue(st)

        #mysize=self.sb1.GetSize()
        #mypos=self.sb1.GetPosition()
        #self.img1 = wx.Image("simpleline.png", wx.BITMAP_TYPE_ANY)
        #self.sb1 = wx.StaticBitmap(self.panel, -1, wx.BitmapFromImage(self.img1),pos=mypos,size=mysize)
        try :
            mypath = './out/'
            for item in self.cpuPics:  
                    img = wx.Image(mypath+item[0], wx.BITMAP_TYPE_ANY)
                    sb = wx.StaticBitmap(self.panel, -1, wx.BitmapFromImage(img),pos=item[1],size=item[2])
        except :
            return

    def OnTimer(self, evt):
        #print 'on timer'
        dc = wx.BufferedDC(wx.ClientDC(self))
        self.Draw(dc)
        self.panel.Refresh()
        
    def OnPaint(self, evt):
        dc = wx.BufferedPaintDC(self)
        #self.Draw(dc)


if __name__ == '__main__':
    app = App()
    app.MainLoop()


class TestFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, title="cpu  memory",size=(1200, 640))
        p = wx.Panel(self)

        fgs = wx.FlexGridSizer(cols=2, hgap=10, vgap=10)


        img1 = wx.Image("simpleline.png", wx.BITMAP_TYPE_ANY)


        #w = img1.GetWidth()
        #h = img1.GetHeight()
        #img2 = img1.Scale(w/2, h/2)

        sb1 = wx.StaticBitmap(p, -1, wx.BitmapFromImage(img1))
        #sb2 = wx.StaticBitmap(p, -1, wx.BitmapFromImage(img2))

        # and put them into the sizer
        fgs.Add(sb1)
        #fgs.Add(sb2)
        p.SetSizerAndFit(fgs)
        #self.Fit()



